package com.ourchem.web.controller.system;


import com.ourchem.common.core.domain.AjaxResult;
import com.ourchem.common.core.domain.model.LoginUser;
import com.ourchem.common.utils.StringUtils;
import com.ourchem.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/check/token")
public class CheckTokenController {

    @Autowired
    TokenService tokenService;

    @PostMapping
    public AjaxResult checkToken(@RequestBody Map<String,String> map){
        if(StringUtils.isEmpty(map.get("token"))){
            return AjaxResult.error("token为空");
        }
        LoginUser user = tokenService.getLoginUserFromToken(map.get("token"));
        if(user==null){
            return AjaxResult.error("token有误");
        }
        if("visitor@qq.com".equals(user.getUser().getEmail())){
            return AjaxResult.success(false);
        }
        return AjaxResult.success(true);
    }
}
